package com.itbuka.goods.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.itbuka.goods.domain.GoodsProduct;
import com.itbuka.goods.mapper.GoodsProductMapper;
import com.itbuka.goods.service.GoodsProductService;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;


import java.util.List;

/**
* @author apple
* @description 针对表【goods_product(商品表)】的数据库操作Service实现
* @createDate 2024-07-30 16:06:25
*/
@Service
public class GoodsProductServiceImpl implements GoodsProductService {
@Autowired
private GoodsProductMapper iGoodsProductMapper;

@Override
public List<GoodsProduct> selectAll() {
LambdaQueryWrapper <GoodsProduct> lqw = new LambdaQueryWrapper<>();
lqw.eq(GoodsProduct::getIsDelete,0);
return iGoodsProductMapper.selectList(lqw);
}


@Override
public List<GoodsProduct> selectList(GoodsProduct iGoodsProduct) {
LambdaQueryWrapper <GoodsProduct> lqw = this.lqw(iGoodsProduct);
return iGoodsProductMapper.selectList(lqw);
}

@Override
public Integer insert(GoodsProduct iGoodsProduct) {
return iGoodsProductMapper.insert(iGoodsProduct);
}

@Override
@Transactional
public Integer delete(String ids) {
try {
String[] split = ids.split(",");
for (String id : split) {
GoodsProduct iGoodsProduct = new GoodsProduct();
iGoodsProduct.setId(Long.parseLong(id));
iGoodsProduct.setIsDelete(1);
iGoodsProductMapper.updateById(iGoodsProduct);
}
return 1;
}catch (Exception e){
return -1;
}
}

@Override
public Integer update(GoodsProduct iGoodsProduct) {
return iGoodsProductMapper.updateById(iGoodsProduct);
}

@Override
public Page<GoodsProduct> pageAll(Integer page, Integer size) {
PageHelper.startPage(page,size);
return (Page<GoodsProduct>)this.selectAll();
}

@Override
public Page<GoodsProduct> pageList(GoodsProduct iGoodsProduct, Integer page, Integer size) {
PageHelper.startPage(page,size);
return (Page<GoodsProduct>)this.selectList(iGoodsProduct);
}

public LambdaQueryWrapper lqw(GoodsProduct iGoodsProduct){
LambdaQueryWrapper <GoodsProduct> lqw = new LambdaQueryWrapper<>();
    if (iGoodsProduct.getId() != null){
    lqw.eq(GoodsProduct::getId,iGoodsProduct.getId());
    }
    if (iGoodsProduct.getName() != null){
    lqw.eq(GoodsProduct::getName,iGoodsProduct.getName());
    }
    if (iGoodsProduct.getPrice() != null){
    lqw.eq(GoodsProduct::getPrice,iGoodsProduct.getPrice());
    }
    if (iGoodsProduct.getSalesModel() != null){
    lqw.eq(GoodsProduct::getSalesModel,iGoodsProduct.getSalesModel());
    }
    if (iGoodsProduct.getType() != null){
    lqw.eq(GoodsProduct::getType,iGoodsProduct.getType());
    }
    if (iGoodsProduct.getStatus() != null){
    lqw.eq(GoodsProduct::getStatus,iGoodsProduct.getStatus());
    }
    if (iGoodsProduct.getAudit() != null){
    lqw.eq(GoodsProduct::getAudit,iGoodsProduct.getAudit());
    }
    if (iGoodsProduct.getShopName() != null){
    lqw.eq(GoodsProduct::getShopName,iGoodsProduct.getShopName());
    }
    if (iGoodsProduct.getClassifyId() != null){
    lqw.eq(GoodsProduct::getClassifyId,iGoodsProduct.getClassifyId());
    }
    if (iGoodsProduct.getSelling() != null){
    lqw.eq(GoodsProduct::getSelling,iGoodsProduct.getSelling());
    }
    if (iGoodsProduct.getParameter() != null){
    lqw.eq(GoodsProduct::getParameter,iGoodsProduct.getParameter());
    }
    if (iGoodsProduct.getUnitMeasure() != null){
    lqw.eq(GoodsProduct::getUnitMeasure,iGoodsProduct.getUnitMeasure());
    }
    if (iGoodsProduct.getImg() != null){
    lqw.eq(GoodsProduct::getImg,iGoodsProduct.getImg());
    }
    if (iGoodsProduct.getVideo() != null){
    lqw.eq(GoodsProduct::getVideo,iGoodsProduct.getVideo());
    }
    if (iGoodsProduct.getDescription() != null){
    lqw.eq(GoodsProduct::getDescription,iGoodsProduct.getDescription());
    }
    if (iGoodsProduct.getIsDelete() != null){
    lqw.eq(GoodsProduct::getIsDelete,iGoodsProduct.getIsDelete());
    }
    if (iGoodsProduct.getCreateTime() != null){
    lqw.eq(GoodsProduct::getCreateTime,iGoodsProduct.getCreateTime());
    }
    if (iGoodsProduct.getUpdateTime() != null){
    lqw.eq(GoodsProduct::getUpdateTime,iGoodsProduct.getUpdateTime());
    }
    if (iGoodsProduct.getBrandId() != null){
    lqw.eq(GoodsProduct::getBrandId,iGoodsProduct.getBrandId());
    }
return lqw;
}
}




